function filterParams(params) {
  let list = []
  params.matched.forEach(el => {
    if (el.meta.title) {
      const listItem = {
        hasRedirect: !!el.redirect,
        name: el.meta.title,
        path: el.path
      }
      list.push(listItem)
    }
  })
  if (list[0].name !== '首页') {
    list = [{
      hasRedirect: true,
      name: '首页',
      path: '/'
    }].concat(list)
  }
  return list
}

const state = {
  breadList: []
}
const mutations = {
  SET_BREADCRUMB_LIST(state, list) {
    state.breadList = list
  }
}

const actions = {
  getBreadList({ commit }, params) {
    return new Promise((resolve, reject) => {
      if (params.matched && params.matched.length > 0) {
        const list = filterParams(params)
        commit('SET_BREADCRUMB_LIST', list)
        console.log(state.breadList)
        resolve()
      } else {
        reject('路由参数错误')
      }
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
